#include "stdafx.h"
#include "WorldBuilder.h"
#include "PickColor.h"

PickColor::PickColor(GLubyte* rgb)
{
    this->rgb[0] = rgb[0];
    this->rgb[1] = rgb[1];
    this->rgb[2] = 255;
}

PickColor::PickColor(GLubyte r, GLubyte g)
{
    rgb[0] = r;
    rgb[1] = g;
    rgb[2] = 255;
}

bool PickColor::operator<(const PickColor & other) const
{
    return std::lexicographical_compare(rgb, rgb + 2, 
                                        other.rgb, other.rgb + 2);
}

bool PickColor::operator==(const PickColor& other) const
{
    return rgb[0] == other.rgb[0] && rgb[1] == other.rgb[1];
}

bool PickColor::operator!=(const PickColor& other) const
{
    return !(*this == other);
}

PickColor& PickColor::operator++() 
{
    ++rgb[0];
    if(rgb[0] == 0)
    {
        ++rgb[1];
        ASSERT(rgb[1] > 0);
    }
    return *this;
}

PickColor PickColor::operator++(int) 
{
    PickColor copy = *this;
    operator++();
    return copy;
}

void PickColor::setSecondaryComponent(GLubyte blue)
{
    rgb[2] = blue;
}

void PickColor::setInRenderContext() const
{
    Color(rgb[0] / 256.f, rgb[1] / 256.f, rgb[2] / 256.f)();
}
